package com.subsequent.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.subsequent.dto.AppointmentsQueryDTO;
import com.subsequent.pojo.Appointments;
import com.subsequent.service.AppointmentsService;
import com.subsequent.mapper.AppointmentsMapper;
import com.subsequent.vo.AppointmentsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
* @author 不.凌
* @description 针对表【appointments(预约挂号表)】的数据库操作Service实现
* @createDate 2025-05-07 14:19:04
*/
@Service
public class AppointmentsServiceImpl extends ServiceImpl<AppointmentsMapper, Appointments>
    implements AppointmentsService{
    @Autowired
    private AppointmentsMapper appointmentsMapper;
    @Override
    public PageInfo<AppointmentsVO> getAppointmentsList(AppointmentsQueryDTO appointmentsQueryDTO) {
        // 启动分页
        PageHelper.startPage(appointmentsQueryDTO.getPageNum(), appointmentsQueryDTO.getPageSize());
        // 查询数据（注意：这里调用 mapper 返回的是 List<AppointmentsVO>）
        List<AppointmentsVO> list = appointmentsMapper.getAppointmentsList(appointmentsQueryDTO);
        // 将结果包装成 PageInfo（自动获取总记录数等信息）
        PageInfo<AppointmentsVO> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int updateStatus(AppointmentsVO appointmentsVO) {
        appointmentsVO.setStatus(1);
        int update = appointmentsMapper.updateStatus(appointmentsVO);
        return update;
    }

    @Override
    public int updateFee(AppointmentsVO appointmentsVO) {
        appointmentsVO.setFee(new BigDecimal(0));
        appointmentsMapper.updateFee(appointmentsVO);
        return 1;
    }
}




